#ifndef _X_LOG_UTIL_H
#define _X_LOG_UTIL_H
#include <iostream>
#define MAX_LOG_LEN 4096
namespace XLog
{
    class XLogUtil
    {
    public:
        static uint32_t GetCurTime()
        {
            return time(NULL);
        }
        static std::string GetTimestampStr2()
        {
            time_t t = GetCurTime();
            tm stTime;
            localtime_r(&t, &stTime);
            tm* aTm = &stTime;
            //       YYYY   year
            //       MM     month (2 digits 01-12)
            //       DD     day (2 digits 01-31)
            //       HH     hour (2 digits 00-23)
            //       MM     minutes (2 digits 00-59)
            //       SS     seconds (2 digits 00-59)
            char buf[20];
            snprintf(buf, 20, "%04d-%02d-%02d %02d:%02d:%02d", aTm->tm_year+1900, aTm->tm_mon+1, aTm->tm_mday, aTm->tm_hour, aTm->tm_min, aTm->tm_sec);
            return std::string(buf);
        }
        static std::string GetTimestampStr(time_t t)
        {
            if ( t == 0 ) t = GetCurTime();
            tm stTime;
            localtime_r(&t, &stTime);
            tm* aTm = &stTime;
            char buf[20];
            snprintf(buf, 20, "%04d-%02d-%02d_%02d-%02d-%02d", aTm->tm_year+1900, aTm->tm_mon+1, aTm->tm_mday, aTm->tm_hour, aTm->tm_min, aTm->tm_sec);
            return std::string(buf);
        }
        static uint32_t GetThreadID()
        {
            return pthread_self();
        }

        static std::string XLOG_VA_LIST_STR(const char* fmt,...)
        {
            char buff[MAX_LOG_LEN] = {0};
            va_list ap;
            va_start(ap, fmt);
            vsnprintf( buff, MAX_LOG_LEN, fmt, ap);
            va_end(ap);
            return buff;
        }

        static bool IsSameDay( uint32_t dwTime1, uint32_t dwTime2 )
        {
            time_t t1 = dwTime1;
            time_t t2 = dwTime2;
            struct tm stcT1;
            struct tm stcT2;
            localtime_r( &t1, &stcT1 );
            localtime_r( &t2, &stcT2 );
            if ( stcT1.tm_year == stcT2.tm_year && stcT1.tm_yday == stcT2.tm_yday )
            {
                return true;
            }
            return false;
        }
    };

}

#endif